<template>
  <div>
    <div id="div">
      <el-button size="mini" @click="print">打印</el-button>
    </div>
    <div v-html="content"></div>
  </div>
</template>

<script>
import Tinymce from '@/components/Tinymce'
import { parseChiefComplaint, parseHPI, parsePastHistory, parsePE, parseCheckout, parseDiagnosis } from '@/utils/index'
import { getTemplate, saveTemplate } from '@/api/print'

export default {
  components: { Tinymce },
  data() {
    return {
      content: ''
    }
  },
  methods: {
    parseChiefComplaint,
    parseHPI,
    parsePastHistory,
    parsePE,
    parseCheckout,
    parseDiagnosis,
    print() {
      let button = document.querySelector('#div').innerHTML
      document.querySelector('#div').children[0].remove()
      window.print()
      document.querySelector('#div').innerHTML = button
    },
    save() {
      saveTemplate(this.content).then(res => {
        if (res.data.result == 'success') {
          this.$message({
            showClose: true,
            message: '保存成功!',
            type: 'success'
          })
        }
      })
    }
  },
  mounted() {

    getTemplate('hospital', 'hospital').then(res => {
      this.content = res.data.template
      console.log(this.tempOpen)
      let tempOpen = JSON.parse(localStorage.getItem('tempOpen'))
      let dictIndex = JSON.parse(localStorage.getItem('dictIndex'))
      let parsedChiefComplaint = parseChiefComplaint(tempOpen.chiefComplaint, dictIndex)
      let parsedHPI = parseHPI(tempOpen.HPI, dictIndex)
      let parsedPastHistory = parsePastHistory(tempOpen.pastHistory, dictIndex)
      let parsedPE = parsePE(tempOpen.PE)
      let parsedDiagnosis = parseDiagnosis(tempOpen.diagnosis)
      let parsedCheckout = parseCheckout(tempOpen)
      this.content = eval('`' + res.data.template + '`')
      // console.log(content)
    })
  },
  computed: {
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
p {
  font-size: initial;
}
h1 {
  text-align: center;
}
</style>